'' Octopilot -- Config.spin
'' (c) 2008-2009 Ben Levitt
'' http://code.google.com/p/octopilot/
''
'' Shared configuration file


CON
  ' Servo Pin order, used for ins and outs
  throttle        =             5
  aileron         =             4
  elevator        =             3
  rudder          =             2
  gear            =             1
  flap            =             0
  NumInChannels   =             6
  NumOutChannels  =             6
  MaxChannels     =             8                       ' Don't change the Max Channels

  autopilotSwitch =             gear


  ' Enable/Disable specific modules
  navigationEnabled =           1
  stabilizationEnabled =        1
  stabilizationProximityEnabled=0
  actionEnabled =               1
  videoOutEnabled =             0 ' Don't enable this unless you're using pcb_v5 or newer, or you move videoPinBase to be a multiple of 4
  
  
  ' If throttle drops below here, it means the failsafe was activated
  throttleLowValue   =          9800
  
  
  ' Servo Reversing settings
  ' These only affect the output.  Set to 1 to reverse a servo.
  aileronReversed =             1
  elevatorReversed=             0
  rudderReversed  =             1
  gearReversed    =             0
  flapReversed    =             0


  ' Flapperon Setting
  ' If this is set to 1, the right aileron is controlled by the flap channel.
  useFlaperons    =             1
  
{{  
  ' IO Pin Layout for octopilot PCB v2
  ' Arranged in sets of 8 pins ('*' means taken, '.' means available)
  inServoBase     = 0   ' 0-5     ******
                        ' 6-7           ..
                                        
  outServoBase    = 8   ' 8-13    ******  
                        ' 14-15         ..
                                        
  servoLedPin     = 16  ' 16      *      
  gpsLedPin       = 17  ' 17       *       
  actionPinBase   = 18  ' 18-19     **
                        ' 20-21       ..
  gpsPinBase      = 22  ' 22-23         **

                        ' 24      .
  imuPinBase      = 25  ' 25-27    ***    
  eepromPinBase   = 28  ' 28-29       **  
  debugPinBase    = 30  ' 30-31         **
}}


  ' IO Pin Layout for octopilot PCB v4
  ' Arranged in sets of 8 pins ('*' means taken, '.' means available)
  inServoBase     = 0   ' 0-5     ******
                        ' 6-7           ..
                                        
  outServoBase    = 8   ' 8-13    ******  
                        ' 14-15         ..

  servoLedPin     = 16  ' 16      *      
  actionPinBase   = 17  ' 17-18    **
  videoPinBase    = 19  ' 19-21      ***           ' Doh!  videoPinBase has to be a multiple of 4.
  gpsPinBase      = 22  ' 22-23         **

                                  
  gpsLedPin       = 24  ' 24      *       
  imuPinBase      = 25  ' 25-27    ***    
  eepromPinBase   = 28  ' 28-29       **  
  debugPinBase    = 30  ' 30-31         **
  

{{
  ' IO Pin Layout for octopilot PCB v5
  ' Arranged in sets of 8 pins ('*' means taken, '.' means available)
  inServoBase     = 0   ' 0-5     ******
                        ' 6-7           ..
                                        
  outServoBase    = 8   ' 8-13    ******  
                        ' 14-15         ..

  videoPinBase    = 16  ' 16-18   ***
  servoLedPin     = 19  ' 19         *      
  actionPinBase   = 20  ' 20-21       **
  gpsPinBase      = 22  ' 22-23         **

                                  
  gpsLedPin       = 24  ' 24      *       
  imuPinBase      = 25  ' 25-27    ***    
  eepromPinBase   = 28  ' 28-29       **  
  debugPinBase    = 30  ' 30-31         **
}}

  
  ' Navigation States
  NavTurningLeft   =            1
  NavTurningRight  =            2
  NavCircling      =            4
  NavApproachingWP =            8
  NavReachedWP     =            16
  NavPassedWP      =            32


PUB setAileron(outValsAddr, defaultValsAddr, deflection)
  ' deflection is a value from -5000 to 5000 with 0 being centered
  if aileronReversed <> 0
    deflection := -deflection
  WORD[outValsAddr+aileron*2] := WORD[defaultValsAddr+aileron*2] + deflection
  if useFlaperons <> 0
    if flapReversed == 1
      deflection := -deflection
    WORD[outValsAddr+flap*2] := WORD[defaultValsAddr+flap*2] + deflection
  

PUB setElevator(outValsAddr, defaultValsAddr, deflection)
  ' deflection is a value from -5000 to 5000 with 0 being centered
  if elevatorReversed <> 0
    deflection := -deflection
  WORD[outValsAddr+elevator*2] := WORD[defaultValsAddr+elevator*2] + deflection
  

PUB setRudder(outValsAddr, defaultValsAddr, deflection)
  ' deflection is a value from -5000 to 5000 with 0 being centered
  if rudderReversed <> 0
    deflection := -deflection
  WORD[outValsAddr+rudder*2] := WORD[defaultValsAddr+rudder*2] + deflection
 